<?php

class HomeView extends AuthView
{
	private $oModel;
	
	public function __construct(HomeModel $model)
	{
		$this->oModel = $model;
	}
	
	protected function title() { return TextManager::i()->text("PAGE_TITLE_HOME", false); }
	
	protected function name() { return "home"; }
	
	protected function content()
	{
		$action = $this->oModel->action();
		$changePassErrors = array();
		$aboutErrors = array();
		
		if ($action == "login")
		{
		?>
		<div><?php TextManager::i()->text("WELCOME_PLAYER"); echo $this->oModel->player()->name(); ?></div>
		<?php
		}
		else if ($action == "change_password")
		{
			$changePassErrors = $this->oModel->errors();
			if (empty($errors)):
			?>
			<div><?php TextManager::i()->text("CHANGED_PASSWORD"); ?></div>
			<?php
			endif;
		}
		else if ($action == "about")
			$aboutErrors = $this->oModel->errors();
		
		$this->changePasswordForm($changePassErrors);
	?>
	<br />
	<?php
		$this->aboutForm($aboutErrors);
	?>
	<a href = "<?php $this->url(array("view" => "city")); ?>"><?php TextManager::i()->text("TO_GAME"); ?></a>
	<?php
	}
	
	private function changePasswordForm($errors)
	{
	?>
	<form action  = "<?php $this->url(array("action" => "change_password")); ?>" method = "POST">
		<table class = "form_table">
			<tr><td colspan = "2" class = "title"><?php TextManager::i()->text("TITLE_CHANGE_PASS"); ?></td></tr>
			<tr><td><?php TextManager::i()->text("OLD_PASSWORD"); ?></td><td><input type = "password" name = "password" /></td></tr>
			<tr><td><?php TextManager::i()->text("NEW_PASSWORD"); ?></td><td><input type = "password" name = "new_password" /></td></tr>
			<tr><td><?php TextManager::i()->text("NEW_REPEAT_PASSWORD"); ?></td><td><input type = "password" name = "new_repeat_password" /></td></tr>
			<tr><td class = "btn" colspan = "2"><input type = "submit" value = "<?php TextManager::i()->text("CHANGE_PASS"); ?>" /></td></tr>
			<?php foreach ($errors as $error): ?>
				<tr><td class = "error" colspan = "2">*<?php TextManager::i()->text($error); ?></td></tr>
			<?php endforeach; ?>
		</table>
	</form>
	<?php
	}
	
	private function aboutForm($errors)
	{
	?>
	<form action = "<?php $this->url(array("action" => "about")); ?>" method = "POST">
		<table class = "form_table">
			<tr><td class = "title"><?php TextManager::i()->text("TITLE_ABOUT"); ?></td></tr>
			<tr<?php if (isset($errors["desc"])): ?> class = "error"<?php endif; ?>><td><textarea rows = "15" cols = "45" name = "about"><?php echo $this->oModel->player()->about(); ?></textarea></td></tr>
			<tr><td class = "btn"><input type = "submit" value = "<?php TextManager::i()->text("ACCEPT"); ?>" /></td></tr>
		</table>
	</form>
	<?php
	}
	
}

?>